# Maintainer:
pkgname=libtls-standalone
pkgver=2.9.1
_namever=${pkgname}${pkgver%.*}
pkgrel=1
pkgdesc="libtls extricated from libressl sources"
url="https://www.libressl.org/"
arch="all"
license="ISC"
depends="ca-certificates-bundle"
depends_dev="openssl-dev"
makedepends_build=""
makedepends_host="libbsd-dev openssl-dev"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc"
source="https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-$pkgver.tar.gz
	Makefile
	tls_compat.c
	tls_compat.h
	test_program.c
	libtls-ciphers.patch
	openssl-1.1.0-bio-method.patch
	openssl-1.1.0-verify-param.patch
	openssl-1.1.0-asn1-string.patch
	openssl-1.1.0-x509-object.patch
	"
libressl_src="$srcdir/libressl-$pkgver"
builddir="$srcdir"

prepare() {
	cd "$builddir"
	rm -rf "$libressl_src"/include/openssl

	cd "$libressl_src"
	patch -p1 < "$srcdir"/libtls-ciphers.patch
	patch -p1 < "$srcdir"/openssl-1.1.0-bio-method.patch
	patch -p1 < "$srcdir"/openssl-1.1.0-verify-param.patch
	patch -p1 < "$srcdir"/openssl-1.1.0-asn1-string.patch
	patch -p1 < "$srcdir"/openssl-1.1.0-x509-object.patch
}

build() {
	cd "$builddir"

	make PREFIX=/usr LIBRESSL_SRCDIR="${libressl_src}" LIBRESSL_VERSION="${pkgver}"
}

check() {
	cd "$builddir"
	make PREFIX=/usr LIBRESSL_SRCDIR="${libressl_src}" LIBRESSL_VERSION="${pkgver}" check
}

package() {
	cd "$builddir"

	make PREFIX=/usr LIBRESSL_SRCDIR="${libressl_src}" LIBRESSL_VERSION="${pkgver}" DESTDIR="${pkgdir}" install
	install -Dm644 "${libressl_src}"/COPYING "$pkgdir"/usr/share/licenses/$pkgname/COPYING
}

sha512sums="7051911e566bb093c48a70da72c9981b870e3bf49a167ba6c934eece873084cc41221fbe3cd0c8baba268d0484070df7164e4b937854e716337540a87c214354  libressl-2.9.1.tar.gz
75292dcd0321a3cb00b30715f537cd35f2375922aac3ad5445f3d7b9eff16ab934926b1605f3330032f8455378c89f41bd1ed83f5a027fc967adff7006ed9486  Makefile
be8216d08a6992ca65a8e3f1e010645833899465090179f269a62de5fcfe2711d463fe1aa57e408492648878fa2ee53377c4509ef48a2aafe3f267cce73e9209  tls_compat.c
0b8fca899e1f7b51979d69458be23c77c1b7f265ed60de76cf5cfb9eb5742111cf50813bd35384831301523a6a0562a20acf1aec22dc0d9ad653271d45ede915  tls_compat.h
71d36fe25c95a0a45497e3f699b01dddcaae9053dd1b1e2419df94272c47024cf6516c51c902129201061601b04a72551904b15a332a4cf53358983b5db73618  test_program.c
8da41dc7f3a3e94c7c26c20b88e649eeaa556064c6b45deb4604fb0b5738109344bf2d9e5c37dc963634db1761370aa5ed4dfe085cae2a21e74535b5b98f4a43  libtls-ciphers.patch
90244db67d2f5a2b4679cd4b905f6e58105e20e5a4648dd0781dee3f3d1ce87350eee9683f2e6e554949a390ee45d2247e7588e75668e82feb68213178905d3d  openssl-1.1.0-bio-method.patch
b0c6c0b32d6ea30b7161ae75e36b8102b3c00268723dec15464318bae8f77a386dba9ef0537d47018b385b16f57132b5c893e494b8853d51b638b4d270e1f9d6  openssl-1.1.0-verify-param.patch
e0b7ce674269714cd63f628c332ed3420086c973f6e763a9a5d57991738370759d437b59edff5349ce4213725588f58e196c479b372a702833fcae75da9d71a1  openssl-1.1.0-asn1-string.patch
7d88088240f78dc3656e71d67f2222b4562bbcfacfaac77e7d8d3ace50ae7f02fac15cea0df2d9990b8d30f6cfd0b4ffd92ea97191181f0b00b1d34c050ef130  openssl-1.1.0-x509-object.patch"
